package com.chang.soul.exception;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**处理全部异常信息
 * @author Administrator
 *
 */
public class ExceptUtil {

	/**异常数据
	 * @param start
	 * @return
	 */
	public static JSONObject ErrorJson(long start) {

		JSONObject result = new JSONObject();
		 JSONArray array = new JSONArray();
		 JSONObject object = new JSONObject();
		 object.put("fail", "data except");
		 array.add(object);
		 result.put("status", ResultCode.FAIL);
         result.put("statusCode", ResultCode.FAIL.code());
         result.put("describe", ResultCode.DATA_ERROR.message());
         result.put("time",  System.currentTimeMillis()-start+"ms");
         result.put("datas", array);
         return result;

	}

	/**删除异常数据
	 * @param start
	 * @return
	 */
	public static JSONObject delJson(long start) {

		JSONObject result = new JSONObject();
		 JSONArray array = new JSONArray();
		 JSONObject object = new JSONObject();
		 object.put("fail", "有外键关联或者有正在执行的操作");
		 array.add(object);
		 result.put("status", ResultCode.FAIL);
         result.put("statusCode", ResultCode.FAIL.code());
         result.put("describe", "删除失败，请先删除关联信息");
         result.put("time",  System.currentTimeMillis()-start+"ms");
         result.put("datas", array);
         return result;

	}


	/**删除异常数据
	 * @param start
	 * @return
	 */
	public static JSONObject delJson(long start,String desc) {

		JSONObject result = new JSONObject();
		 JSONArray array = new JSONArray();
		 JSONObject object = new JSONObject();
		 object.put("fail", "处理异常");
		 array.add(object);
		 result.put("status", ResultCode.FAIL);
         result.put("statusCode", ResultCode.FAIL.code());
         result.put("describe", desc);
         result.put("time",  System.currentTimeMillis()-start+"ms");
         result.put("datas", array);
         return result;

	}










	/**参数异常数据
	 * @param start
	 * @return
	 */
	public static JSONObject ParameterExceptJson(long start) {

		JSONObject result = new JSONObject();
		 JSONArray array = new JSONArray();
		 JSONObject object = new JSONObject();
		 object.put("fail", "请求参数异常");
		 array.add(object);
		 result.put("status", ResultCode.FAIL);
         result.put("statusCode", ResultCode.FAIL.code());
         result.put("describe", ResultCode.DATA_ERROR.message());
         result.put("time",  System.currentTimeMillis()-start+"ms");
         result.put("datas", array);
         return result;

	}



	/**正常数据
	 * @param start
	 * @return
	 */
	public static JSONObject SuccessJson(long start,JSONArray array) {
		JSONObject result = new JSONObject();
		 result.put("status", ResultCode.SUCCESS);
         result.put("statusCode", ResultCode.SUCCESS.code());
         result.put("describe", ResultCode.SUCCESS.message());
         result.put("time",  System.currentTimeMillis()-start+"ms");
         result.put("datas", array);
         return result;

	}


}
